<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="/Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="/Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="/Css/style.css" />
    <script type="text/javascript" src="/Js/jquery.js"></script>
<!--    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>-->
    <script type="text/javascript" src="/Js/bootstrap.js"></script>
    <script type="text/javascript" src="/Js/ckform.js"></script>
    <script type="text/javascript" src="/Js/common.js"></script>
	<script type="text/javascript" src="/Js/layui/layui.all.js"></script>

</head>
<body>
<form class="form-inline definewidth m20" action="" method="get">    
   <table>
		<tr>
			<td align="right">原密码:</td><td><input id="p1" type="password"/></td>
		</tr>
		<tr>
			<td align="right">新密码:</td><td><input id="p2"  type="password"/></td>
		</tr>
		<tr>
			<td align="right">确认密码:</td><td><input id="p3" type="password"/></td>
		</tr>
		<tr>
			<td colspan="2" align="center"><br/>
				<input id="sb" type="button" value="保存" class="btn btn-primary"/>
			</td>
		</tr>
   </table>
</form>
</body>
<script>
	$(function () {
		$("#p1").blur(function(){
			let name = $("#p1").val();
			if (name == ""){
				layer.msg("原密码不能为空")
			}else {
				//查询原密码是否正确
				$.ajax({
					type: "get",
					dataType: "JSON",
					url: "/passwordCorrect",
					data: {p1:name},
					success: function(data){
						if (data.code == -1) {
							layer.msg("原密码不正确，请检测")
						}
					},
					error: function(msg){
						layer.msg("err")
					}
				});
			}
		});
		$("#p2").blur(function(){
			let name = $("#p2").val();
			let name1 = $("#p1").val();
			if (name == ""){
				layer.msg("新密码不能为空")
			}else if (name.length < 6) {
				layer.msg("新密码强度不够！")
			}else if (name == name1 && name1 != ""){
				layer.msg("新密码与原密码相同，请检测")
			}
		});
		$("#p3").blur(function(){
			let name1 = $("#p3").val();
			let name2 = $("#p2").val();
			if (name2 != "" && name1 == ""){
				layer.msg("请再输入一次新密码")
			}else if (name1 != name2) {
				layer.msg("新密码两次输入不一致")
			}
		});
	})
</script>
<script>
	$(function () {
		$("#sb").click(function () {
			let p1 = $("#p1").val();
			let p2 = $("#p2").val();
			let p3 = $("#p3").val();
			if (p1 == "") {
				layer.msg("原密码不能为空")
			}else if (p2 == "") {
				layer.msg("新密码不能为空")
			}else if (p3 == "") {
				layer.msg("请再次输入新密码")
			}else if (p2 != p3) {
				layer.msg("新密码两次输入不一致")
			}else if (p1 == p2) {
				layer.msg("新密码与原密码一致")
			}else if (p2.length < 6 || p3.length < 6) {
				layer.msg("新密码强度不够！")
			}else {
				let win = layer.load(0);
				$.ajax({
					type: "get",
					dataType: "JSON",
					url: "/updatePassword",
					data: {p1:p1,p2:p2},
					success: function(data){
						if (data.code == 0) {
							layer.msg("修改成功！")
							$("#p1").val('');
							$("#p2").val('');
							$("#p3").val('');
						}else {
							layer.msg("原密码不正确，请检测")
						}
						layer.close(win)
					},
					error: function(msg){
						layer.msg("err")
						layer.close(win)
					}
				});
			}
		})
	})
</script>
</html>